import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
import VueRouter from 'unplugin-vue-router/vite'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import tailwindcss from '@tailwindcss/vite'

const config = {
  plugins: [
    tailwindcss(),
    VueRouter({
      routesFolder: 'src/views',
      dts: 'types/typed-router.d.ts',
      extensions: ['.vue', '.ts', '.tsx']
    }),
    vue(),
    AutoImport({
      eslintrc: {
        enabled: true
      },
      // 自动导入类型
      dts: 'types/auto-imports.d.ts',
      imports: [
        'vue',
        'vue-router',
        'pinia',
        {
          'alova/client': ['useRequest'],
          '@/services': ['request']
        }
      ],
      dirs: ['./src/components', './src/stores', './src/utils']
    }),
    Components({
      resolvers: [ElementPlusResolver()]
    })
  ],
  server: {
    port: 9090
  },
  css: {
    preprocessorOptions: {
      scss: { api: 'modern-compiler' }
    }
  },
  resolve: {
    alias: { '@': path.resolve(__dirname, 'src') }
  }
}

export default defineConfig(config)
